package com.sky.chapter1.waitAndnotify;


/**
 * description : 当一个线程调用共享对象的wait方法被挂起后，如果其他线程中断了该线程，则该线程会抛出interruptException异常并返回。
 *
 * @author : 陈庆彪
 * create: 2020-06-26 19:49
 **/
public class waitNotifyInterrupt {
    static Object obj = new Object();

    public static void main(String[] args) throws InterruptedException {
        //创建线程
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("----begin----");
                    //阻塞当前线程
                    synchronized (obj) {
                        obj.wait();
                    }
                    System.out.println("---end---");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        threadA.start();
        Thread.sleep(1000);
        System.out.println("---begin interrupt threadA---");
        threadA.interrupt();
        System.out.println("---end interrupt threadA---");
    }

}
